#pragma once
#include"HashTable.h"
namespace zjs
{
	template <class K,class V,class Hash=HashFun<K>>
	class unordered_map {
		struct KeyOfData {
			const K& operator()(const pair<K,V>& kv)
			{
				return kv.first;
			}
		};
	public:
		typedef typename HashBucket<K, pair<const K, V>, Hash, KeyOfData>::iterator iterator;
		typedef typename HashBucket<K, pair<const K, V>, Hash, KeyOfData>::const_iterator const_iterator;
		pair<iterator, bool> insert(const pair<K, V>& data)
		{
			return _hb.insert(data);
		}

		V& operator[](const K& key)
		{
			auto ret = _hb.insert(make_pair(key, V()));
			return ret.first->second;
		}

		iterator begin()
		{
			return _hb.begin();
		}

		iterator end()
		{
			return _hb.end();
		}

		const_iterator begin() const
		{
			return _hb.begin();
		}

		const_iterator end() const
		{
			return _hb.end();
		}

		iterator find(const K& key)
		{
			return _hb.find(key);
		}

		bool erase(const K& key)
		{
			return _hb.erase(key);
		}

		iterator erase(iterator pos)
		{
			return _hb.erase(pos);
		}


		size_t bucket_count() 
		{ 
			return _hb.BucketCount();
		}

		size_t bucket_size(const K& key) 
		{ 
			return _hb.BucketSize(key);
		}

		size_t size()const
		{
			return _hb.size(); 
		}
		
		bool empty()const 
		{
			return _hb.empty(); 
		}
	private:
		HashBucket<K, pair<const K,V>,Hash, KeyOfData>_hb;
	};
}